import * as sdk from './fetch';

const controllerName = 'iplandBaseController';

/**
 *
 * 根据游戏类型查询游戏是否可玩
 *
 */
async function getGameBaseConfig(params): Promise<wmBaseResponseString> {
  let result = await sdk.post<wmBaseResponseString>(`game-base-config/getInfoByGameType`, {
    ...params,
  });
  return result;
}

/**
 *
 * 获取乐园导航引导数据
 *
 */
async function getNavigationData(params): Promise<wmBaseResponseString> {
  let result = await sdk.post<wmBaseResponseString>(`game-base-config/list`, {
    ...params,
  });
  return result;
}

/**
 *
 * 会员每日登录领取魔力币
 *
 */
async function dailyLoginGetCoin(delFlag): Promise<any> {
  let result = await sdk.get('/customer/daily/login/get/magic/coin?delFlag=' + delFlag, {});
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 *
 * 魔力值榜单
 *
 */
async function magicValueList(params): Promise<wmBaseResponseString> {
  let result = {
    context: '',
    code: '',
    message: '',
  };
  try {
    result = await sdk.post<any>(`leaderboard/charts`, {
      ...params,
    });
  } catch (e) {
    result = e;
  }
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 *
 * 奖品
 *
 */
async function leaderboardRewards(params): Promise<wmBaseResponseString> {
  let result = await sdk.post('/leaderboard/rewards', params);
  return result;
}

/**
 *
 * 任务列表
 *
 */
async function getTaskList(): Promise<wmBaseResponseString> {
  let result = await sdk.get('/gametaskcustomercenter/list', {});
  // return result;
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 *
 * 我的道具
 *
 */
async function getMyProp(params): Promise<wmBaseResponseString> {
  let result = await sdk.post('/mybackpack/page', params);
  return result.context;
}

/**
 *
 * 首页道具
 *
 */
async function getPropCount(params): Promise<wmBaseResponseString> {
  let result = await sdk.post('/mybackpack/count', params);
  return result.context;
}

/**
 *
 * 宝箱分页
 *
 */
async function treasureBoxPage(params): Promise<wmBaseResponseString> {
  let result = await sdk.post('/treasurebox/page', params);
  return result.context;
}

/**
 *
 * 宝箱list
 *
 */
async function treasureBoxList(): Promise<wmBaseResponseString> {
  let result = await sdk.post('/treasurebox/list', {});
  return result.context;
}

/**
 * 查询游戏可用次数
 */
async function getGameTimesConfigInfo(params = {}): Promise<any> {
  let result = await sdk.post<any>(`customergamecount/find-current-user-available-game-count`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 抽奖
 * @param params
 */
async function gameScratch(params = {}): Promise<any> {
  let result = {
    context: '',
    code: '',
    message: '',
  };
  try {
    result = await sdk.post<any>(`game-base-config/scratchCard`, {
      ...params,
    });
  } catch (e) {
    result = e;
  }
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 查询每日游戏可用次数
 */
async function getGameDailyTimes(params = {}): Promise<any> {
  let result = await sdk.post<any>(`customergamecount/find-current-user-over-game-count`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

export default {
  getGameBaseConfig,
  getNavigationData,
  dailyLoginGetCoin,
  magicValueList,
  leaderboardRewards,
  getTaskList,
  getMyProp,
  getPropCount,
  treasureBoxPage,
  treasureBoxList,
  getGameTimesConfigInfo,
  gameScratch,
  getGameDailyTimes,
};

/**
 * 列表数据
 */
export interface esGoodsInfoPage {
  esGoodsInfoPage?: esGoodsInfoPageDetail;
  [k: string]: any;
}
export interface esGoodsInfoPageDetail {
  /**
   * 具体数据内容
   */
  content?: ContentDetailVO[];
  empty?: boolean;
  first?: boolean;
  last?: boolean;
  /**
   * 页码
   */
  number?: number;
  numberOfElements?: number;
  /**
   * 每页条数
   */
  size?: number;
  sort?: null;
  /**
   * 总数据大小
   */
  total?: number;
  totalElements?: number;
  totalPages?: number;
  [k: string]: any;
}

export interface ContentDetailVO {
  goodsInfo?: goodsInfoDetailVO[];
  id?: number;
}

export interface goodsInfoDetailVO {
  goodsInfoImg?: string;
  goodsInfoName?: string;
  marketPrice?: number;
}

/**
 * 万米请求返回
 */
export interface wmBaseResponseString {
  /**
   * 结果码
   */
  code: string;
  /**
   * 内容
   */
  context?: esGoodsInfoPage;
  /**
   * 错误内容
   */
  errorData?: {
    [k: string]: any;
  };
  /**
   * 状态
   */
  success?: boolean;
  /**
   * 消息内容
   */
  message?: string;
  [k: string]: any;
}

/**
 * 正常请求返回
 */
export interface BaseResponseString {
  /**
   * 结果码
   */
  code: string;
  /**
   * 内容
   */
  data?: {
    [k: string]: any;
  };
  /**
   * 错误内容
   */
  errorData?: {
    [k: string]: any;
  };
  /**
   * 状态
   */
  success?: boolean;
  /**
   * 消息内容
   */
  message?: string;
  [k: string]: any;
}
